# -*- coding: utf-8 -*-
# @Time    : 2022/4/8 16:52
# @Author  : zyw
# @Email   : panda_kings@163.com
# @File    : login_dec.py
from flask import g
from functools import wraps


def login_required(func):
    """强制登录装饰器"""
    # wraps 是返回装饰器,参数是传来的函数,
    @wraps(func)
    def wrapper(*args, **kwargs):
        print("func的名字是>>", func.__name__)
        if g.user_id is not None:
            return func(*args, **kwargs)
        return {'code': 401, 'message': '无效token 账号为空'}

    return wrapper


